<template>
  <a-card :bordered="false">
    <a-divider orientation="left">微信账户</a-divider>
    <a-form :form="formwx">
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账户名称">
        <a-input placeholder="账户名称" v-decorator="['accountName', {rules: [{required: true, message: '账户名称'}]}]" />
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账号">
        <a-input placeholder="账号" v-decorator="['accountNo', {rules: [{required: true, message: '账号'}]}]" />
      </a-form-item>

      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label=" ">
        <a-button style="margin-right:5px;">返回</a-button>
        <a-button @click="saveWX" type="primary">保存</a-button>
      </a-form-item>
    </a-form>
    <a-divider orientation="left">支付宝账户</a-divider>
    <a-form :form="formzfb">
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账户名称">
        <a-input placeholder="账户名称" v-decorator="['accountName', {rules: [{required: true, message: '账户名称'}]}]" />
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账号">
        <a-input placeholder="账号" v-decorator="['accountNo', {rules: [{required: true, message: '账号'}]}]" />
      </a-form-item>

      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label=" ">
        <a-button style="margin-right:5px;">返回</a-button>
        <a-button @click="saveZFB" type="primary">保存</a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import { getOilAccount } from '@/api/api'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "OilAccountList",
    mixins: [JeecgListMixin],
    components: {

    },
    data() {
      return {
        description: '加油站账户管理页面',
        // 表头
        columns: [],
        modelwx:{
          id: '',
          accountName: '',
          accountNo: ''
        },
        modelzfb:{
          id: '',
          accountName: '',
          accountNo: ''
        },
        confirmLoading: false,
        formwx: this.$form.createForm(this),
        formzfb: this.$form.createForm(this),
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        url: {
          list: "/lww/oilAccount/list",
          add: "/lww/oilAccount/add",
          edit: "/lww/oilAccount/edit",
          delete: "/lww/oilAccount/delete",
          deleteBatch: "/lww/oilAccount/deleteBatch",
        },
      }
    },
    computed: {

    },
    created() {
      let that = this;
      getOilAccount({accountType: 0}).then((res)=>{
        if(res.success){
          that.modelwx = res.result;
          that.$nextTick(() => {
              that.formwx.setFieldsValue(pick(that.modelwx,'accountNo','accountName'))
          //时间格式化
            });
        }
      }).finally(() => {
      })
      getOilAccount({accountType: 1}).then((res)=>{
        if(res.success){
          that.modelzfb = res.result;
          that.$nextTick(() => {
              that.formzfb.setFieldsValue(pick(that.modelzfb,'accountNo','accountName'))
          //时间格式化
            });
        }
      }).finally(() => {
      })
    },
    methods: {
      saveWX() {
        const that = this;
        // 触发表单验证
        this.formwx.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.modelwx.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.modelwx.accountType = "0";
            console.log(values)
            let formData = Object.assign(this.modelwx, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        })
      },
      saveZFB() {
        const that = this;
        // 触发表单验证
        this.formzfb.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.modelzfb.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            this.modelzfb.accountType = "1";
            let formData = Object.assign(this.modelzfb, values);
            //时间格式化
            
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
        })
      }
    }
  }
</script>
<style scoped>
  /* @import '~@assets/less/common.less' */
</style>
